<template>
	<view class="main_box">
		<view class="fix_title">
			信息收集
		</view>
		<view class="txt">
			请填写交行Ⅰ类户信息
		</view>
		<view class="form_box">
			<view class="inp">
				<view class="left">
					姓名
				</view>
				<view class="right">
					<input type="text" placeholder="请输入姓名" @blur="userNameBlur" v-model.trim="form.user_name">
				</view>
			</view>
			<view class="warn">
				{{oneWarn?'!只能输入中文':''}}
			</view>
			<view class="inp">
				<view class="left">
					一类卡卡号
				</view>
				<view class="right">
					<input type="text" placeholder="请输入一类卡卡号" @blur="oneCountBlur" v-model.trim="form.one_countNo">
				</view>
			</view>
			<view class="warn">
				{{fourWarn?'!只能填写交通银行卡号':''}}
			</view>

			<view class="inp">
				<view class="left">
					身份证号码
				</view>
				<view class="right">
					<input type="text" placeholder="请输入身份证号码" @blur="idCardBlur" v-model.trim="form.id_cardNo">
				</view>
			</view>
			<view class="warn">
				{{twoWarn?'!身份证号码格式错误':''}}
			</view>

			<view class="inp">
				<view class="left">
					手机号码
				</view>
				<view class="right">
					<input type="text" placeholder="请输入手机号码" adjust-position="false" @blur="phoneBlur" v-model.trim="form.phone_number">
				</view>
			</view>
			<view class="warn">
				{{threeWarn?'!手机号码格式错误':''}}
			</view>

			<view class="inp">
				<view class="left">
					一类卡行名
				</view>
				<view class="right">
					<input type="text" placeholder="输入一类卡自动查询" disabled v-model.trim="form.one_countName">
				</view>
			</view>
		</view>
		<view class="boxBt">
			<view class="btnLeft" @click="callBack">
				上一步
			</view>
			<view class="btn" @click="getOver">
				完成
			</view>
		</view>
		<view class="kdn">
			<image src="/static/images/blank/4341yu.png" mode=""></image>
			<view class="subx">
				交通银行 提供产品服务
			</view>
		</view>
	</view>
</template>

<script>
	import {
		oneCountInfo,
		getBlankName
	} from "@/common/api/blank"
	import {
		_showLoading,
		_showToast
	} from '../../common/js/util.js'

	export default {
		data() {
			return {
				form: {
					user_name: "",
					id_cardNo: "",
					phone_number: "",
					one_countNo: "",
					one_countName: ""
				},
				oneWarn: false,
				twoWarn: false,
				threeWarn: false,
				fourWarn: false,
				orgId: "",
			}
		},
		onLoad(option) {
			this.orgId = option.orgId
			// console.log(this.orgId)
		},
		methods: {
			callBack() {
				uni.navigateBack()
			},
			userNameBlur(e) {
				let exp = /^[\u4e00-\u9fa5]{2,8}$/
				if (!exp.test(e.target.value)) {
					this.form.user_name = ""
					this.oneWarn = true
				} else {
					this.oneWarn = false
				}
			},
			idCardBlur(e) {
				let _IDRe18 =
					/^([1-6][1-9]|50)\d{4}(18|19|20)\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
				let _IDre15 = /^([1-6][1-9]|50)\d{4}\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}$/
				// 校验身份证：
				console.log(!(_IDRe18.test(e.target.value) || _IDre15.test(e.target.value)), )
				if (!(_IDRe18.test(e.target.value) || _IDre15.test(e.target.value))) {
					this.form.id_cardNo = ""
					this.twoWarn = true
				} else {
					this.twoWarn = false
				}
			},
			phoneBlur(e) {
				let exp = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
				if (!exp.test(e.target.value)) {
					this.form.phone_number = ""
					this.threeWarn = true
				} else {
					this.threeWarn = false
				}
			},
			oneCountBlur(e) {
				let exp = /^([1-9]{1})(\d{15}|\d{16}|\d{18})$/
				if (!exp.test(e.target.value)) {
					this.form.one_countNo = ""
					this.form.one_countName = ""
					this.fourWarn = true
				} else {
					getBlankName({
						cardBin: this.form.one_countNo,
						orgId: this.orgId
					}).then((res) => {
						console.log(res)
						if (res.code == 0 && res.data != null && res.data.bankName) {
							this.fourWarn = false
							this.form.one_countName = res.data.bankName
						} else {
							this.form.one_countName = ""
							this.form.one_countNo = ""
							this.fourWarn = true
							_showToast("该卡非交通银行一类卡，请重新绑定。")
						}
					}).catch((err) => {
						console.log(err)
						_showToast(err)
						this.form.one_countNo = ""
						this.form.one_countName = ""
						this.fourWarn = true
					})
				}
			},
			getOver() {
				if (!(this.form.phone_number && this.form.user_name && this.form.id_cardNo && this.form.one_countNo && this.form.one_countName)) {
					_showToast("请填写正确的表单格式")
				} else {
					let user_Id = uni.getStorageSync("s_userId")
					console.log({
						userId: user_Id,
						mobileNo: this.form.phone_number,
						userName: this.form.user_name,
						idNo: this.form.id_cardNo,
						cardNo: this.form.one_countNo,
						cardBankName: this.form.one_countName,
						orgId: this.orgId
					})
					oneCountInfo({
						userId: user_Id,
						mobileNo: this.form.phone_number,
						userName: this.form.user_name,
						idNo: this.form.id_cardNo,
						cardNo: this.form.one_countNo,
						cardBankName: this.form.one_countName,
						orgId: this.orgId
					}).then((res) => {
						if (res.code == 0) {
							uni.redirectTo({
								url: `/pageBlank/successfulOpen/successfulOpen?batId=${res.data.batId}&orgId=${this.orgId}`
							})
						} else {
							_showToast(res.msg)
						}
					}).catch((err) => {
						_showToast(err)
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.main_box {
		.kdn {
			margin: 86rpx 0rpx;
			width: 100%;
			display: flex;
			justify-content: center;
			align-items: center;

			>image {
				width: 34rpx;
				height: 33rpx;
			}

			.subx {
				margin-left: 8rpx;
				height: 34rpx;
				font-size: 23rpx;
				font-weight: 400;
				color: #003A79;
				line-height: 34rpx;
			}
		}

		box-sizing: border-box;
		overflow-y: auto;

		::v-deep .picker-view {
			width: 100%;
			height: 500rpx;
			box-sizing: border-box;
			padding-top: 40rpx;

			picker-view-column {
				margin: 0 10rpx;
			}
		}

		.item {
			height: 50px;
			line-height: 50rpx;
			font-size: 20rpx;
			align-items: center;
			justify-content: center;
			text-align: center;
		}

		.popup-content {
			height: 720rpx;
			background-color: #fff;
			position: fixed;
			bottom: 0rpx;
			left: 0rpx;
			width: 100%;
			margin: 0rpx;

			.nbs {
				width: 100%;
				height: 120rpx;
			}

			.busp {
				display: flex;
				justify-content: space-between;

				.bLeft {
					width: 100rpx;
					height: 80rpx;
					line-height: 80rpx;
					text-align: center;
				}

				.bRight {
					width: 100rpx;
					height: 80rpx;
					line-height: 80rpx;
					text-align: center;
				}
			}
		}

		.popup-height {
			height: 100%;
			flex: 1;
			width: 200px;
			background-color: green;
		}

		.form_box {
			display: flex;
			flex-direction: column;
			align-items: center;

			.warn {
				width: 650rpx;
				height: 40rpx;
				background: #FFFFFF;
				opacity: 1;
				display: flex;
				justify-content: flex-end;
				color: red;
				font-size: 28rpx;
			}

			.inp {
				width: 650rpx;
				height: 87rpx;
				background: #FFFFFF;
				border-radius: 8rpx;
				opacity: 1;
				border: 2rpx solid #E6E6E6;
				display: flex;

				input {
					width: 650rpx;
					height: 87rpx;
					box-sizing: border-box;
					padding-left: 21rpx;
					font-size: 28rpx;
				}

				.left {
					margin-left: 21rpx;
					width: 169rpx;
					height: 87rpx;
					line-height: 87rpx;
					font-size: 28rpx;
					font-weight: 500;
					color: #000;
					text-align-last: justify
				}

				.right_s {
					display: flex;
					width: 430rpx;
					justify-content: space-between;
					align-items: center;
					margin-left: 23rpx;

				}

				.right {
					flex: 1;
					height: 87rpx;
					line-height: 87rpx;
					margin-left: 23rpx;
					font-size: 28rpx;
					font-weight: 400;
					color: #333333;

					>input {
						width: 100%;
						height: 87rpx;
						padding: 0;
					}

				}
			}

			.inp:last-child {
				margin-bottom: 68rpx;
			}
		}

		.boxBt {
			display: flex;
			justify-content: center;

			.btn {
				width: 358rpx;
				height: 88rpx;
				line-height: 88rpx;
				text-align: center;
				background: #3478F5;
				box-shadow: 0rpx 3rpx 26rpx 1rpx rgba(55, 98, 244, 0.58);
				border-radius: 44rpx 44rpx 44rpx 44rpx;
				opacity: 1;
				font-size: 32rpx;
				font-weight: 300;
				color: #FFFFFF;
			}

			.btnLeft {
				width: 314rpx;
				height: 88rpx;
				line-height: 88rpx;
				text-align: center;
				background: #FFFFFF;
				box-shadow: 0rpx 3rpx 26rpx 1rpx rgba(0, 0, 0, 0.1);
				border-radius: 44rpx 44rpx 44rpx 44rpx;
				opacity: 1;
				border: 1rpx solid #666666;
				font-size: 32rpx;
				font-weight: 400;
				color: #333333;
				margin-right: 22rpx;
			}
		}


		.fix_title {
			margin: 30upx 0 60upx 0;
			font-size: 40upx;
			font-weight: bolder;
			display: flex;
			align-items: center;
			margin-left: 10rpx;

			&::before {
				content: '';
				height: 36upx;
				width: 12upx;
				background-image: linear-gradient(to bottom, #c3defc, #007AFF);
				margin-right: 12upx;
				border-radius: 6upx;
			}
		}

		.txt {
			height: 46rpx;
			font-size: 32rpx;
			font-weight: 500;
			color: #020202;
			line-height: 46rpx;
			margin-bottom: 68rpx;
			margin-left: 32rpx;
			margin-top: 56rpx;
		}
	}
</style>
